/**
 * 
 */
package com.zufangbao.earth.handler.impl;

import java.io.File;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.zufangbao.earth.handler.FileHandler;

/**
 * @author lute
 *
 */
@Service("fileHandler")
public class LocalFileHandler implements FileHandler {
	
	@Value("#{config['file.upload']}")
	private String uploadPath;
	
	/* (non-Javadoc)
	 * @see com.zufangbao.earth.handler.FileHandler#save(java.lang.String, java.io.InputStream)
	 */
	public String save(String fileName, InputStream inputStream) {
		
		try {
			File file = new File(this.uploadPath + fileName);
			FileUtils.copyInputStreamToFile(inputStream, file);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fileName;
	}
	
	/* (non-Javadoc)
	 * @see com.zufangbao.earth.handler.FileHandler#delete(java.lang.String)
	 */
	public void delete(String fileName) {
		FileUtils.deleteQuietly(new File(this.uploadPath + fileName));
	}

}
